home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr47 / asmlib40.zip / STARTUP.ASM < prev    next >
Assembly Source File  |  1995-02-05  |  2KB  |  97 lines

  1. ; STARTUP.ASM for ASM16 version 4.0 or greater
  2. ; Copyright (C) 1994 Douglas Herr
  3. ;  all rights reserved
  4.  
  5. include    asm.inc
  6.  
  7. extrn    meminit:proc
  8. extrn    breaktrap:proc
  9. extrn    breakrelease:proc
  10. extrn    mymain:proc
  11.  
  12. ; make LINK search through the ASM16 library for external references
  13. ; so I don't have to specify the library on the command line
  14. IF codesize EQ 1
  15. IF datasize EQ 2
  16.     IFDEF    NOXT
  17.     includelib    asm286h
  18.     ELSE
  19.     includelib    asm86h
  20.     ENDIF
  21. ELSE
  22.     IFDEF    NOXT
  23.     includelib    asm286m
  24.     ELSE
  25.     includelib    asm86m
  26.     ENDIF
  27. ENDIF
  28. ELSE
  29.     IFDEF    NOXT
  30.     includelib    asm286s
  31.     ELSE
  32.     includelib    asm86s
  33.     ENDIF
  34. ENDIF
  35.  
  36. ; declare CODE segment before DATA segment
  37. .code
  38. @curseg    ends
  39.  
  40. stacksize    equ    1024
  41.  
  42. .stack stacksize
  43.  
  44. .data
  45. public    pspseg
  46. pspseg        dw    ?        ; storage for PSP segment
  47.  
  48. .code
  49. start:
  50. ; start by pointing DS to DGROUP
  51.     mov    dx,@data
  52.     mov    ds,dx
  53.     assume    ds:@data
  54.  
  55. ; adjust for MS-LINK bug that puts SS in wrong segment
  56. ; THIS ADJUSTMENT IS REQURIED BY SEVERAL ASM16 SUBROUTINES
  57.     mov    ax,ss
  58.     sub    ax,dx            ; paragraph difference
  59.     mov    cl,4
  60.     shl    ax,cl            ; converted to bytes
  61.     add    sp,ax            ; fix SP for new SS
  62.     mov    ss,dx            ; assume ss:DGROUP
  63.  
  64. ; save PSP segment for programs running under DOS 2.xx
  65.     mov    pspseg,es
  66.  
  67. ; Release memory beyond the end of the program.  This makes dynamic
  68. ; memory allocation possible.  MEMINIT does this automatically, as well
  69. ; as initializing the near heap.  When it's done, MEMINIT self destructs,
  70. ; leaving only a RET in case it's called again.
  71. ;
  72. ; CAUTION: Borland's TD debugger has trouble tracing through the self-
  73. ; destructing part of MEMINIT.  If you are using TD, step over MEMINIT
  74. ; instead of tracing through it.
  75.  
  76.     mov    bx,0FFFFh        ; request dynamic heap allocation
  77.     mov    ax,32767        ; heap size requested
  78.     call    meminit
  79.  
  80. ; prevent an unintended program crash; trap Ctrl+Break, Ctrl+C and
  81. ; Ctrl+Alt+Del key combinations
  82.     call    breaktrap
  83.  
  84. ; call your main program here
  85.     call    mymain
  86.  
  87. exit:
  88. ; de-activate the Ctrl+Break trap
  89.     call    breakrelease
  90.  
  91. ; normal program exit
  92.     mov    ax,4C00h
  93.     int    21h
  94.  
  95. end    start
  96.     end
  97.